package com.xuzz.study.thread.lock;

import java.util.concurrent.atomic.AtomicReference;

public class SpinLock {
    private AtomicReference<Thread> cas = new AtomicReference<>();
    public void lock()
    {
        Thread thread = Thread.currentThread();
        while(!cas.compareAndSet(null,thread))
        {

        }
    }

    public void unlock()
    {
        Thread thread = Thread.currentThread();
        cas.compareAndSet(thread,null);
    }
}
